﻿/******************************************************************************
 * 
 * Announce: CSharpKit, Basic algorithms, components and definitions.
 *           Copyright (C) ShenYongchen.
 *           All rights reserved.
 *   Author: 申永辰.郑州 (shenyczz@163.com)
 *  WebSite: http://github.com/shenyczz/CSharpKit
 *
 * THIS CODE IS LICENSED UNDER THE MIT LICENSE (MIT).
 * THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 
 * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
 * IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
 * PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 * 
******************************************************************************/

using System;

namespace CSharpKit.Numerics.LinearAlgebra
{
    /// <summary>
    /// 矢量工厂
    /// </summary>
    public static class VectorFactory
    {
        /// <summary>
        /// 使用存储构造一个矢量
        /// </summary>
        /// <param name="storage"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Vector<T> WithStorage<T>(VectorStorage<T> storage)
            where T : struct, IFormattable, IEquatable<T>
        {
            return Vector<T>.Builder.OfStorage(storage);
        }

        /// <summary>
        /// 生成一个等同于输入矢量且元素均为0的新矢量
        /// </summary>
        /// <param name="example"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Vector<T> SameAs<T>(in Vector<T> example)
            where T : struct, IFormattable, IEquatable<T>
        {
            return Vector<T>.Builder.SameAs(example);
        }

        /// <summary>
        /// 生成一个等同于输入矢量且元素均为0的新矢量
        /// </summary>
        /// <param name="example"></param>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TU"></typeparam>
        /// <returns></returns>
        public static Vector<T> SameAs<T, TU>(Vector<TU> example)
            where T : struct, IFormattable, IEquatable<T>
            where TU : struct, IFormattable, IEquatable<TU>
        {
            return Vector<T>.Builder.SameAs(example);
        }


        /// <summary>
        /// 根据数组生成一个密集矢量
        /// </summary>
        /// <param name="array"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Vector<T> Dense<T>(T[] array)
            where T : struct, IFormattable, IEquatable<T>
        {
            return Vector<T>.Builder.Dense(array);
        }



        /// <summary>
        /// 产生一随机矢量
        /// </summary>
        /// <param name="length">矢量长度</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Vector<T> Random<T>(int length)
           where T : struct, IFormattable, IEquatable<T>
        {
            return Vector<T>.Builder.Random(length);
        }






        //}}@@@
    }


}

